package com.iphanta.community.following.service.impl;

import com.baidu.fsg.uid.UidGenerator;
import com.iphanta.community.common.utils.JsonUtils;
import com.iphanta.community.following.entity.Dynamic;
import com.iphanta.community.following.mapper.DynamicMapper;
import com.iphanta.community.following.service.TestDynamicService;
import com.iphanta.community.following.traffic.PublishDynamicRequest;
import com.iphanta.community.following.traffic.PublishDynamicResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Random;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 3/2/22 7:13 PM
 */
@Service
public class TestDynamicServiceImpl implements TestDynamicService {

    @Autowired
    private DynamicMapper dynamicMapper;

    @Resource
    private UidGenerator idGenerator;


    @Override
    public PublishDynamicResponse publishDynamic(PublishDynamicRequest request) {
        Random random = new Random();
        for (int i = 101100; i < 103100; i++) {
            int count = random.nextInt(20);
            for (int j = 0; j < count; j++) {
                Dynamic dynamic = new Dynamic();
                dynamic.setId(this.idGenerator.getUID());
                dynamic.setUid(String.valueOf(i));
                dynamic.setResJson(JsonUtils.INSTANCE.toJsonString(request.getResURIs()));
                dynamic.setContext("Test_" + i);
                dynamic.setDynamicType(0);
                if (j % 2 == 0) {
                    dynamic.setMediaType("image");
                } else {
                    dynamic.setMediaType("video");
                }
                dynamic.setIsDel(0);
                dynamic.setUpdateTime(new Date());
                dynamic.setCreateTime(new Date());
                dynamicMapper.insert(dynamic);
            }

        }

        PublishDynamicResponse response = new PublishDynamicResponse();
        response.setDynamicId(0L);
        return response;
    }
}
